#! -*- coding: utf-8 -*-
import uuid

from flask import Flask, request
from flask_cors import CORS
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session

from config.database_config import DatabaseConfig
from apps.ID_sme.cdc_career import controls as cdc_career_control
from apps.ID_sme.tx_platform import controls as tx_platform_control
from apps.ID_sme.ugo_dashboard import controls as ugo_dashboard_control

app = Flask("ID-obj-204")
CORS(app, supports_credentials=True, resources={r"/*": {"origins": "*"}})
app.config.from_object(DatabaseConfig)

# db.init_app(app)

app.register_blueprint(tx_platform_control.bp, url_prefix="/b/sme/tx")
app.register_blueprint(cdc_career_control.bp, url_prefix="/b/sme/cdc/career")
app.register_blueprint(ugo_dashboard_control.bp, url_prefix="/b/sme/ugo/dashboard")

app.config["ENGINES"] = {
    "sme_tx_platform": scoped_session(sessionmaker(bind=create_engine(app.config["DATABASES"]["sme_tx_platform"], pool_size=16, max_overflow=16))),
    "sme_cdc_career": scoped_session(sessionmaker(bind=create_engine(app.config["DATABASES"]["sme_cdc_career"], pool_size=16, max_overflow=16))),
    "sme_ugo_dashboard": scoped_session(sessionmaker(bind=create_engine(app.config["DATABASES"]["sme_ugo_dashboard"], pool_size=16, max_overflow=16))),
}

@app.before_request
def before_request():
    request.request_id = str(uuid.uuid4())


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=18080, debug=True)
